package com.Ruier.service.imp;

import com.Ruier.dao.AccountDao;
import com.Ruier.pojo.Account;
import com.Ruier.service.AccountService;
import com.Ruier.utils.Uploadfile;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AccountServiceImp implements AccountService {
    @Autowired
    private AccountDao accountDao;
    @Autowired
    private Uploadfile uploadfile;
    @Override
    public boolean checkUserName(String username) {
        LambdaQueryWrapper<Account> lqw=new LambdaQueryWrapper<>();
        lqw.eq(Account::getUserName,username);
        Account account = accountDao.selectOne(lqw);
        if (account!=null){
            return false;
        }
        return true;
    }

    @Override
    public boolean login(Account account) {
        LambdaQueryWrapper<Account> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(Account::getUserName,account.getUserName())
               .eq(Account::getUserPwd,account.getUserPwd());
        Account accountExist = accountDao.selectOne(wrapper);
        if(accountExist!=null){
            return true;
        }else return false;
    }

    @Override
    public void addAccount(Account account) {
        accountDao.insert(account);
    }
}
